<?php
/**
 * 选购平台(默认)
 * Enter description here ...
 * @author nijn
 *
 */
class IndexController extends FrontController{

	/**
	 * indexAction 选购平台首页
	 * registerAction 选购平台注册
	 * logoutAction 选购平台注销
	 * loginAction 选购平台登录
	 */
    public $layout = '//layouts/platform_column';
    
    public function actionIndex(){
        $this->render('index',array('model'=>new AdminLoginForm()));
    }
 
    public function actionRegister($type = 'ProviderAccount') {
    	$provider = new ProviderAccount('register');
    	$dealer = new DealerAccount('register');
    	$modelName  = $type;
    	
		if ($type == 'ProviderAccount') {
			$model = $provider;
    	} else {
    		$model = $dealer;
    	}
    	
    	if (isset($_POST[$modelName])) {
				$model->attributes = $_POST[$modelName];
				if ($model->save()) {
					$login = new AdminLoginForm();
					$login->username = $model->worker_name;
					$login->password = $model->worker_password;
					$login->login();
					$this->redirect(array('index'));
				}
				if ($type == 'ProviderAccount') {
					$provider = $model;
				} else 
					$dealer = $model;
			}
    	
    	$this->render('register',array(
    		'provider'=>$provider,'dealer'=>$dealer
    	));	
    }
    
 	public function actions() {
    	return array(
    		'captcha'=>array(
				'class'=>'CCaptchaAction',
				'backColor'=>0xFFFFFF,
				'minLength' => 4,
				'maxLength' => 4,
				'width' => '80',
				'height' => '40',
				'testLimit' => 0
			),
			'login' => array(
    			'class' => 'application.components.actions.front.LoginAction',
    			'modelName' => 'AdminLoginForm',
//    			'returnUrl' => array('index'),
    		    'view' => 'login'
    		),
    		'logout' => array(
    			'class' => 'application.components.actions.front.LogoutAction',
    			'user' => 'adminUser',
    			'returnUrl' => array('index'),
    		),
    	);
    }
}

?>